package com.example.springmvc.common;

import java.util.List;

/**
 * 统一接口分页响应结构
 *
 * @author fanhang
 */
public class PageResult<T> extends WebResult<List<T>> {
    private final Page page;

    public PageResult(List<T> dataList, Integer pageNum, Integer pageSize, Long total, int pages) {
        super(ResultCode.WEB_RESULT_SUCCESS.getCode(), null, dataList);
        this.page = new Page(pageNum, pageSize, total, pages);
    }

    public PageResult(PageResponse<?> pageResponse, List<T> dataList) {
        this(dataList, pageResponse.getPageNum(), pageResponse.getPageSize(), pageResponse.getTotal(), pageResponse.getPages());
    }

    public Page getPage() {
        return page;
    }

    public static final class Page {
        /**
         * 当前页
         */
        private final Integer pageNum;
        /**
         * 每页行数
         */
        private final Integer pageSize;
        /**
         * 总数量
         */
        private final Long total;
        /**
         * 页数
         */
        private final int pages;

        public Page(Integer pageNum, Integer pageSize, Long total, int pages) {
            this.pageNum = pageNum;
            this.pageSize = pageSize;
            this.total = total;
            this.pages = pages;
        }

        public Integer getPageNum() {
            return pageNum;
        }

        public Integer getPageSize() {
            return pageSize;
        }

        public Long getTotal() {
            return total;
        }

        public int getPages() {
            return pages;
        }
    }
}
